{{>head}}

	<div class="row">
		<div class="game">
			<div class="row gameRow">
				<div class="col-lg-4 col-sm-4 col-4">
					<div class="gameData"><span class="balance">{{balance}}</span> BTC</div>
					Credits
				</div>
				<div class="col-lg-4 col-sm-4 col-4">
					<div class="gameData">.001 BTC</div>
					Bet Amount
				</div>
				<div class="col-lg-4 col-sm-4 col-4">
					<div class="gameData"><span class="jackpot">{{slotsJackpot}}</span> BTC</div>
					Winner Paid
				</div>
			</div>
			<div class="text-center">
				<div class="odds">
					<p class="sm-margin">Jackpot
						<span class="pull-right">
							<img src="/assets/img/icon-bitcoin.jpg" class="payout-icon">
							<img src="/assets/img/icon-bitcoin.jpg" class="payout-icon">
							<img src="/assets/img/icon-bitcoin.jpg" class="payout-icon">
						</span>
					</p>
					<p class="sm-margin">10 x .001 BTC
						<span class="pull-right">
							<img src="/assets/img/icon-cherry.jpg" class="payout-icon">
							<img src="/assets/img/icon-cherry.jpg" class="payout-icon">
							<img src="/assets/img/icon-cherry.jpg" class="payout-icon">
						</span>
					</p>
					<p class="sm-margin">10 x .001 BTC
						<span class="pull-right">
							<img src="/assets/img/icon-bitcoin.jpg" class="payout-icon">
							<img src="/assets/img/icon-bitcoin.jpg" class="payout-icon">
						</span>
					</p>
					<p class="sm-margin">5 x .001 BTC
						<span class="pull-right">
							<img src="/assets/img/icon-cherry.jpg" class="payout-icon">
							<img src="/assets/img/icon-cherry.jpg" class="payout-icon">
						</span>
					</p>
					<p class="sm-margin">2 x .001 BTC
						<span class="pull-right">
							<img src="/assets/img/icon-bitcoin.jpg" class="payout-icon">
						</span>
					</p>
					<p class="sm-margin">1 x .001 BTC
						<span class="pull-right">
							<img src="/assets/img/icon-cherry.jpg" class="payout-icon">
						</span>
					</p>
				</div>
			</div>
			<!-- <div class="text-center" style="height: 45px">
				<h2 class="results"></h2>
			</div> -->
			<div class="text-center">
				<ul class="slot">
					<li><div class="slot-icon slot-icon-bell"></div></li>
					<li><div class="slot-icon slot-icon-drink"></div></li>
					<li><div class="slot-icon slot-icon-lemon"></div></li>
					<li><div class="slot-icon slot-icon-gloves"></div></li>
					<li><div class="slot-icon slot-icon-melon"></div></li>
					<li><div class="slot-icon slot-icon-ring"></div></li>
					<li><div class="slot-icon slot-icon-bitcoin"></div></li>
					<li><div class="slot-icon slot-icon-woman"></div></li>
					<li><div class="slot-icon slot-icon-watch"></div></li>
					<li><div class="slot-icon slot-icon-cherry"></div></li>
				</ul>
			</div>
			<div class="text-center">
				<input type="button" id="play" value="Spin!" class="btn btn-default btn-large btn-spin">
			</div>
			<div class="text-center">
				<input type="checkbox" class="mute"> Mute
			</div>
		</div>
	</div>


<script src="/assets/js/jquery.slots.js"></script>
<script src="/assets/js/jquery.easing.js"></script>
<script>

var balance = parseFloat($(".balance").html());
var jackpot = parseFloat($(".jackpot").html());
var paid = false;

var playSound = function(sound){
	if(!$(".mute").is(":checked")){
		if(sound=="win")
			var audio = new Audio("/assets/sounds/cash-register-01.wav");
		else if(sound=="spin")
			var audio = new Audio("/assets/sounds/spin-slots.mp3");
		audio.play();
	}
}

var won = function (ammount){
	if(paid){
		balance = balance + ammount;
		balance = Number(balance.toFixed(3));
		$(".balance").html(balance);
		$(".results").html("You won!");
		playSound("win");
	}else{
		$(".results").html("You won!");
		playSound("win");
	}
	$(".results").fadeIn();
}

var lost = function(){
	$(".results").html("You lost, try again!");
	$(".results").fadeIn();
}

var checkForWin = function(numbers){
	$(".jackpot").html(jackpot);
	if(numbers[2]==7 && numbers[1]==7 && numbers[0]==7){
		won(jackpot);
	}else if(numbers[2]==10 && numbers[1]==10 && numbers[0]==10){
		won(.01);
	}else if(numbers[2]==7 && numbers[1]==7){
		won(.01);
	}else if(numbers[2]==10 && numbers[1]==10){
		won(.005);
	}else if(numbers[2]==7){
		won(.002);
	}else if(numbers[2]==10){
		won(.001);
	}else{
		lost();
	}
}

var clearResults = function(){
	$(".results").fadeOut();
	playSound("spin");
	if(balance > .001){
		balance = balance - .001;
		balance = Number(balance.toFixed(3));
		paid = true;
		$(".balance").html(balance);
	}else
		paid = false;
}

$('.slot').jSlots({
	number : 3,
	winnerNumber : 7,
	spinner : '#play',
	easing : 'easeOutSine',
	onEnd : checkForWin,
	onStart : clearResults,
	loops : 6
});

$(function(){
	$(".slot").each(function(key, slot){
		var random = Math.floor((Math.random()*10));
		var top = random * -140;
		$(slot).css("top",top);
	});
});
</script>

{{>foot}}